package cn.akwangl.concurrency.web.model;

import cn.akwangl.concurrency.web.common.Result;
import cn.akwangl.concurrency.web.model.items.pojo.ItemsCommentsEntity;
import cn.akwangl.concurrency.web.model.items.service.ItemsCommentsService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 测试controller.
 *
 * @author 阿坤同学
 * @date 2022-11-22 14:51
 */
@Slf4j
@RestController
@RequestMapping("/test")
public class TestController {

    private ItemsCommentsService itemsCommentsService;

    @Autowired
    public void setItemsCommentsService(ItemsCommentsService itemsCommentsService) {
        this.itemsCommentsService = itemsCommentsService;
    }

    @GetMapping("/printLog")
    public Result printLog(@RequestParam("content") String content) {
        log.info("日志打印测试:{}", content);
        return Result.success();
    }

    @GetMapping("/getItemsCommentList")
    public Result getItemsCommentList() {
        List<ItemsCommentsEntity> list = itemsCommentsService.list();
        return Result.success(list);
    }

    @GetMapping("/getItemsCommentPage")
    public Result getItemsCommentPage(@RequestParam("pageIndex") Integer pageIndex,
                                      @RequestParam("pageSize") Integer pageSize) {
        Page page = itemsCommentsService.page(new Page(pageIndex, pageSize));
        return Result.success(page);
    }

    @GetMapping("/getItemsCommentOne")
    public Result getItemsCommentOne(@RequestParam("itemsCommentId") String itemsCommentId) {
        return Result.success(itemsCommentsService.getById(itemsCommentId));
    }
}
